package com.sebiotec.ambassador.ui.activity;

import android.widget.TextView;

import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.CommonObserver;
import com.sebiotec.ambassador.R;
import com.sebiotec.ambassador.R2;
import com.sebiotec.ambassador.model.response.SiginResponse;
import com.sebiotec.ambassador.net.BookApiHelper;
import com.sebiotec.ambassador.ui.view.LoadingDialog;
import com.sebiotec.basecommon.utils.base.BaseActivity;
import com.sebiotec.basecommon.utils.constant.SjmConstant;
import com.sebiotec.basecommon.utils.language.LocalManageUtil;
import com.sebiotec.basecommon.utils.tools.ActivityTool;
import com.sebiotec.basecommon.utils.tools.SPUtils;
import com.sebiotec.basecommon.utils.tools.ToastTool;

import java.util.HashMap;

import butterknife.BindView;


public class WecomeActivity extends BaseActivity {


    @BindView(R2.id.textView)
    TextView textView;
    private String BookId;
    private long exitTime=0;

    @Override
    protected int setLayoutId() {
        return R.layout.wecome_land;
    }

    @Override
    protected void initUI() {
        BookId  = getIntent().getStringExtra("BookId");
    }

    @Override
    protected void initData() {

        LoadingDialog loadingDialog = new LoadingDialog(ActivityTool.getInstance().getLastActivity());
        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(SjmConstant.LOGINID,""));
        map.put("Token", SPUtils.get(SjmConstant.TOKEN,""));
        map.put("Lang", LocalManageUtil.getSMJSetLanguageLocales(ActivityTool.getInstance().getLastActivity()));

        BookApiHelper.geRadomApi()
                .getJobSign(map,BookId)
                .compose(Transformer.<SiginResponse>switchSchedulers(loadingDialog))
                .subscribe(new CommonObserver<SiginResponse>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(SiginResponse s) {
                        textView.setText(s.getSignboardInfo());

                    }
                });

    }

    @Override
    protected void setListener() {

    }

    @Override
    public void onBackPressed() {

        if ((System.currentTimeMillis() - exitTime) > 2000) {
            ToastTool.showError(this,getString(R.string.quit));

            exitTime = System.currentTimeMillis();
        } else {
           ActivityTool.getInstance().popOneActivity(this);

        }


    }

}
